<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Province_setting_entity{
	var $current_dbprefix = "";
	var $id = 0;
	var $province ="";
	var $country_id ="";
	
	function __construct() {
		$ci= & get_instance();
		$this->current_dbprefix = $ci->db->dbprefix;
		$ci->db->set_dbprefix('default_');
	}
	function __destruct() {
		$ci= & get_instance();
		$ci->db->set_dbprefix($this->current_dbprefix);
	}
	
	function setId($input){
		$this->id=$input;
	}
	function setProvince($input){
		$this->province=$input;
	}
	function setCountryId($input){
		$this->country_id=$input;
	}
	function getId(){
		return $this->id;
	}
	function getProvince(){
		return $this->province;
	}
	function getCountryId(){
		return $this->country_id;
	}
	
	function init($cmd, $input)
	{
		$ci=& get_instance();
		if($cmd == 'id'){
			$result = $ci->db->where('id',$input)->get(TBL_PROVINCE_SETTING)->result();
		}else if($cmd == 'country_id'){
			$result = $ci->db->where('country_id',$input)->get(TBL_PROVINCE_SETTING)->result();
		}else{
			return false;
		}
		if( !empty($result) ){
			$this->id = $result[0]->id;
			$this->province = $result[0]->province;
			$this->country_id = $result[0]->country_id;
			return $this;
		}
		return false;
	}
	function getLanguageList(){
		$ci=& get_instance();
		return $ci->db->get(TBL_PROVINCE_SETTING)->result();
	}
	function save(){
		$ci=& get_instance();
		$ci->db->set('province',$this->getProvince());
		$ci->db->set('country_id',$this->getCountryId());
		$ci->db->insert(TBL_PROVINCE_SETTING);
		return $ci->db->insert_id();
	}
	function update(){
		$ci=& get_instance();
		$ci->db->set('province',$this->getProvince());
		$ci->db->set('country_id',$this->getCountryId());
		return $ci->db->where('id', $this->id)->update(TBL_PROVINCE_SETTING);
	}
	function delete($id){
		$ci=& get_instance();
		$ci->db->where('id',$id);
		$ci->db->delete(TBL_PROVINCE_SETTING);
	}
}